using System.Reflection;
using UnityEditor;
using UnityEngine;

[CustomPropertyDrawer(typeof(TestButtonCallAttribute))]
public class TestButtonCallAttribute_Drawer : PropertyDrawer
{
    private const int height = 5;

    public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
    {
        return base.GetPropertyHeight(prop, label) + height;
    }

    public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
    {
        TestButtonCallAttribute att = (TestButtonCallAttribute)attribute;
        if (GUI.Button(position, att.headerName))
        {
            string methodName = fieldInfo.Name.Replace("_TestBtn", string.Empty);
            Object cs = prop.serializedObject.targetObject;
            MethodInfo mi = cs.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            if (null != mi)
            {
                mi.Invoke(cs, null);
            }
        }
    }
}